{template "header.html"}
<!-- end header -->
<link href="{THEME_PATH}assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.css" rel="stylesheet" type="text/css" />
<script src="{THEME_PATH}assets/global/plugins/fuelux/js/spinner.min.js" type="text/javascript"></script>
<script src="{THEME_PATH}assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.js" type="text/javascript"></script>


<script type="text/javascript" src="{THEME_PATH}assets/js/sku.js"></script>
<script type="text/javascript">
    $(function () {
        $(".dr_buy_num").TouchSpin({
            step: 1,
            min: 1,
            max: 9999999
        });
        $(".dr_buy_num").change(function () {
            var num = $(this).val();
            var iid = $(this).attr('iid');
            $.ajax({
                type: "GET",
                url: '/index.php?s=cart&c=api&m=update&id='+iid+'&num='+num,
                dataType: "jsonp",
                success: function (json) {
                    dr_tips(json.code, json.msg);
                    if (json.code) {
                        $('#dr_cart_nums').html(json.data.nums);
                        $('#dr_total_'+iid).html(json.data.total);
                    }
                },
                error: function(HttpRequest, ajaxOptions, thrownError) {
                    alert(HttpRequest.responseText);
                }
            });
        });
    });
    function dr_delete_cart_all(name) {

        $('.checkboxes_'+name).each(function() {
            var checked = jQuery(this).is(":checked");
            if (checked) {
                dr_cart_del(jQuery(this).val());
            }
        });
    }
    // ajax提交
    function dr_ajax_order_submit(name) {


        var loading = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 100000000
        });


        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{dr_url('cart/order/index')}",
            data: $("#myform_"+name).serialize(),
            success: function(json) {
                layer.close(loading);
                if (json.code == 1) {
                    dr_tips(1, json.msg);
                    setTimeout("window.location.href = '"+json.data.url+"'", 2000);
                } else {
                    dr_tips(0, json.msg);
                    $('#dr_row_'+json.data.id).addClass('has-error');
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                layer.closeAll('loading');
                alert(HttpRequest.responseText);
            }
        });
    }
</script>

<section class="main-content-area">
    <div class="container">
        <!-- bradcame start -->
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="greentect_bradcame">
                    <ul>
                        <li><a href="{SITE_URL}">首页</a></li>
                        <li>购物车</li>
                    </ul>
                </div>
            </div>
        </div>
        <!-- bradcame end -->


            {loop $my_list $dir $m}
                <form class="form-horizontal" method="post" role="form" id="myform_{$dir}">
                {$form}

                <div class="portlet light bordered" style="box-shadow:0 0px 0px 0px rgba(0,0,0,.03)">
                    <div class="portlet-title">
                        <div class="caption">
                            <span class="caption-subject ">{$module[$dir][name]}</span>
                        </div>
                    </div>
                    {loop $m $cid $list}
                        <div class="portlet-body  ">
                            <h3 style="margin-bottom: 10px"><a href="{$mall[$cid]['url']}" target="_blank">{$mall[$cid]['name']}</a></h3>
                            <table class="table table-bordered table-checkable  ">
                                <thead>
                                <tr>
                                    <th width="50">
                                        <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                            <input checked="checked" type="checkbox" class="group-checkable" data-set=".checkboxes_{$dir}_{$cid}" />
                                            <span></span>
                                        </label>
                                    </th>
                                    <th class="cart_product">商品</th>
                                    <th>详情</th>
                                    <th class="">单价</th>
                                    <th>数量</th>
                                    <th class="">总价</th>
                                    <th  class="action"></th>
                                </tr>
                                </thead>
                                <tbody>

                                {loop $list $i $t}
                                {php $sku_name=dr_string2array($t.sku_name);}
                                <tr id="dr_row_{$t.id}">
                                    <td style="">
                                        <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                            <input type="checkbox" checked="checked" class="checkboxes_{$dir} checkboxes_{$dir}_{$cid}" name="ids[]" value="{$t.id}" />
                                            <span></span>
                                        </label>
                                    </td>
                                    <td class="cart_product">
                                        <a href="{$t.url}" title="{$t.title}"><img src="{dr_thumb($t.thumb, 70, 70)}"></a>
                                    </td>
                                    <td class="cart_description">
                                        <p class="product-name"> <a href="{$t.url}" title="{$t.title}">{dr_strcut($t.title, 50)}</a></p>
                                        {loop $sku_name $i $c}
                                        <small class="cart_ref">{$i}: {$c} </small>
                                        {/loop}
                                    </td>
                                    <td class="price pprice">
                                        {if $t.yuan}
                                        <p>￥<span class="regular-price">{number_format($t.price, 2)}</span>元</p>
                                        <p class="pyuan">￥<span>{number_format($t.yuan, 2)}</span>元</p>
                                        <p>{$t.p_info}</p>
                                        {else}
                                        ￥<span class="regular-price">{number_format($t.price, 2)}</span>元
                                        {/if}
                                    </td>
                                    <td class="qty" style="width: 150px">
                                        <input class="dr_buy_num" iid="{$t.id}" type="text" value="{$t.quantity}">
                                    </td>
                                    <td class="price">
                                        ￥<span id="dr_total_{$t.id}" class="regular-price">{number_format($t.price * $t.quantity, 2)}</span>元
                                    </td>
                                    <td class="action">
                                        <a href="javascript:dr_cart_del('{$t.id}');">删除</a>
                                    </td>
                                </tr>
                                {/loop}
                                </tbody>
                            </table>
                        </div>
                    {/loop}
                    <table class="table  table-checkable  ">
                        <tfoot>
                        <tr>
                            <td class="action" style="width: 50px;">
                                <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                    <input checked="checked" type="checkbox" class="group-checkable" data-set=".checkboxes_{$dir}" />
                                    <span></span>
                                </label>
                            </td>
                            <td colspan="7" class="text-left">
                                <label><button type="button" onclick="dr_delete_cart_all('{$dir}')" class="btn red btn-sm"> <i class="fa fa-trash"></i> {dr_lang('删除')}</button></label>
                                <label><button type="button" onclick="dr_ajax_submit('{FC_NOW_URL}', 'myform_{$dir}', 1000, '{FC_NOW_URL}')" class="btn green btn-sm"> <i class="fa fa-refresh"></i> {dr_lang('刷新')}</button></label>
                                <label><button type="button" onclick="dr_ajax_order_submit('{$dir}')" class="btn green btn-sm"> <i class="fa fa-rmb"></i> {dr_lang('立即下单结算')}</button></label>
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
                </form>

            {/loop}


    </div>
</section>


{template "footer.html"}